home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Direct3D / EffectParam / EffectParam.fx < prev    next >
Encoding:
Text File  |  2004-09-27  |  2.6 KB  |  79 lines

  1. //--------------------------------------------------------------------------------------
  2. // File: EffectParam.fx
  3. //
  4. // The effect file for the EffectParam sample.  
  5. // 
  6. // Copyright (c) Microsoft Corporation. All rights reserved.
  7. //--------------------------------------------------------------------------------------
  8.  
  9.  
  10. //--------------------------------------------------------------------------------------
  11. // Global variables
  12. //--------------------------------------------------------------------------------------
  13. shared float4x4 g_mWorldView : WORLDVIEW;                     // World view matrix
  14. shared float4x4 g_mWorldViewProjection : WORLDVIEWPROJECTION; // World * View * Projection matrix
  15. shared float4x4 g_mViewInv;                                   // Inverse of view matrix
  16. shared float4 g_vLight = float4( 0.0f, 0.0f, -10.0f, 1.0f );  // Light position in view space
  17. shared float4 g_vLightColor = float4( 1.0f, 1.0f, 1.0f, 1.0f );
  18. texture  g_txScene;
  19. float4   Diffuse : MATERIALDIFFUSE;
  20.  
  21.  
  22. sampler2D g_samScene =
  23. sampler_state
  24. {
  25.     Texture = <g_txScene>;
  26.     MinFilter = Linear;
  27.     MagFilter = Linear;
  28.     MipFilter = Linear;
  29. };
  30.  
  31.  
  32. void VertScene( float4 vPos : POSITION,
  33.                 float3 vNormal : NORMAL,
  34.                 float2 vTex0 : TEXCOORD0,
  35.                 out float4 oDiffuse : COLOR0,
  36.                 out float4 oPos : POSITION,
  37.                 out float2 oTex0 : TEXCOORD0 )
  38. {
  39.     // Transform the position from object space to homogeneous projection space
  40.     oPos = mul( vPos, g_mWorldViewProjection );
  41.  
  42.     // Compute view space position
  43.     float4 wPos = mul( vPos, g_mWorldView );
  44.  
  45.     // Compute view space normal
  46.     float3 N = normalize( mul( vNormal, (float3x3)g_mWorldView ) );
  47.  
  48.     float3 InvL = g_vLight - wPos;
  49.     float LengthSq = dot( InvL, InvL );
  50.  
  51.     InvL = normalize( InvL );
  52.     oDiffuse = saturate( dot( N, InvL ) ) * Diffuse * g_vLightColor;// / LengthSq;
  53.  
  54.     // Just copy the texture coordinate through
  55.     oTex0 = vTex0;
  56. }
  57.  
  58.  
  59. float4 PixScene( float4 Diffuse : COLOR0,
  60.                  float2 Tex0 : TEXCOORD0 ) : COLOR0
  61. {
  62.     // Lookup mesh texture and modulate it with diffuse and light color
  63.     return tex2D( g_samScene, Tex0 ) * Diffuse;
  64. //    return float4( tex2D( g_samScene, Tex0 ).xyz, 1.0f ) * Diffuse;
  65. }
  66.  
  67.  
  68. //--------------------------------------------------------------------------------------
  69. // Techniques
  70. //--------------------------------------------------------------------------------------
  71. technique RenderScene
  72. {
  73.     pass P0
  74.     {
  75.         VertexShader = compile vs_1_1 VertScene();
  76.         PixelShader  = compile ps_1_1 PixScene();
  77.     }
  78. }
  79.